public class AufgabeWaren19 { // public static int foobar = 0; public static Helper h = new Helper(); /* Deklaration weiterer Klassenvariablen */ private static String[] waren = new String[]{ "Ayran", "Schokoriegel", "Stifte", "Briefmarken", "Kaugummis", "Gummibärchen" }; private static int[] lager = new int[]{ 99, 70, 53, 490, 30, 10 }; private static double[] preise = new double[]{ 1.995, 1.305, 0.999, 0.854, 2.490, 3.00 }; public static void main(String[] arg) { h.dblIndent = 8; h.intIndent = 5; h.stringIndent = 15; h.currSub = 100; // printLager(waren, lager, preise); printLager(); menu_main(); } public static void menu_verkauf() { int ware = 0, anzahl = 0, cnt = 0; while ( true ) { h.print("\n === Verkauf ===\n"); // Warenliste for ( cnt = 0; cnt < waren.length; cnt++ ) { h.print( (cnt+1) + ". " + waren[cnt] + "\n"); } // Option zum Beenden h.print( 0 + ". " + "Beenden" + "\n"); ware = Read.getInt("Ware: "); if ( ware == 0 ) { return; } else { anzahl = Read.getInt("Anzahl: "); // verkauf(ware, anzahl); 1 } } } public static void menu_main() { int choice = 0; while ( true ) { h.print("\n\n === Menu ===\n" + "1. Ware Verkaufen\n" + "2. Lagerbestand anzeigen\n" + "9. Programm Verlassen\n"); choice = Read.getInt("Auswahl: "); if ( choice == 1 ) { menu_verkauf(); } else if ( choice == 2 ) { printLager(); } else if ( choice == 9 ) { return; // Funktion verlassen } } } public static void printLager() { int n; double einzelWert = 0.0; for ( n = 0; n < waren.length; n++ ) { einzelWert = lager[n] * preise[n]; h.print( h.indent( waren[n] )+ ": " + h.indent( lager[n] )+ " " + h.indent(preise[n] )+ " Euro " + h.indent(einzelWert) + " Euro\n" ); } h.print( h.indent("Lager Gesamt: ") + // h.indent(25, gesamtWert(lager, preis) ) + " Euro" h.indent(25, gesamtWert() ) + " Euro" ); } /* zweite printLager-Funktion */ public static void printLager(String ware) { for (int i = 0; i < waren.length; i++) { if (waren[i] == (ware)) { double einzelWert = lager[i] * preise[i]; h.print( h.indent( waren[i]) + ": " + h.indent( lager[i]) + " " + h.indent( preise[i]) + " Euro " + h.indent(einzelWert) + " Euro\n"); return; // Sobald die Ware gefunden wurde, wird die Funktion beendet } } // Wenn die Ware nicht gefunden wurde, wird eine Fehlermeldung ausgegeben h.print("Ware '" + ware + "' nicht gefunden.\n"); } /* Funktion gesamtWert */ public static double gesamtWert() { double gesamt = 0.0; for (int n = 0; n < lager.length; n++) { gesamt += lager[n] * preise[n]; } return gesamt; } }